package com.linktrip.devicesmanager.main;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import com.linktrip.devicemanager.util.ByteUtil;

public class DeviceTestMain3 {
	public static byte[] temp = { 0x36, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, (byte) 0xa5, 0x0a, 0x07, 0x56,
			(byte) 0x97, (byte) 0xac, (byte) 0xc5, 0x09, 0x01, 0x01, 0x64, 0x11, 0x00, 0x00, 0x00, 0x2b, (byte) 0xda,
			0x1c, (byte) 0xe7, 0x36, 0x19, 0x3f, 0x40, 0x32, 0x1e, (byte) 0xa5, 0x12, (byte) 0x9e, 0x60, 0x5e, 0x40,
			(byte) 0xe1, 0x07, 0x05, 0x05, 0x13, 0x06, 0x32, 0x00, 0x01, 0x19, 0x2c, 0x1e, 0x2a, 0x00, 0x00, 0x74 };
	public static byte[] temp2 = { 0x3e, 0x00, 0x02, 0x00, 0x10, 0x30, 0x00, 0x00, 0x24, (byte) 0xa5, 0x0a, 0x07, 0x56,
			(byte) 0x97, (byte) 0xac, (byte) 0xc5, 0x01, 0x01, 0x01, 0x62, 0x11, 0x00, 0x00, 0x30, (byte) 0xae, 0x5c,
			0x14, (byte) 0xe2, 0x36, 0x19, 0x3f, 0x40, 0x5c, (byte) 0x9d, 0x52, 0x14, (byte) 0x9e, 0x60, 0x5e, 0x40,
			(byte) 0xe1, 0x07, 0x05, 0x05, 0x13, 0x06, 0x0b, 0x00, 0x01, 0x18, 0x2b, 0x23, 0x2a, 0x00, 0x00,
			(byte) 0x84, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };

	public static int count = 0;

	public static void main(String[] args) throws Exception {
		// new DeviceTestMain().deviceConnector();
		// Socket socket = new Socket("test.linktrip.com", 9000);
		threadCount(4000);
	}
	
	public static void threadCount(int count){
		for(int i = 0;i< count;i++){
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					try {
						doSomeThing();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}).start();
		}
	}
	
	public static void doSomeThing() throws IOException{
		Socket socket = new Socket("test.linktrip.com", 8881);
		System.out.println(socket.isConnected());

	//	OutputStream out = socket.getOutputStream();
//		DataOutputStream dout = new DataOutputStream(out);
//		dout.write(temp2);
//		dout.flush();
//		System.out.println("24378165697ac5b wrote done!");
//
//		// read
		DataInputStream dRead = new DataInputStream(socket.getInputStream());
//
//		int len = 0;
//		len = dRead.readShort();
//		byte[] data = new byte[len];
//		dRead.read(data);
//		ByteUtil.printBytes(data);

//		do {
//			len = dRead.readShort();
//			if (len > 0) {
//				byte[] data = new byte[len];
//				dRead.read(data);
//				ByteUtil.printBytes(data);
//			}
//		} while (len <= 0);

//		dout.close();
//		dRead.close();
//		socket.close();
	}

}